package zfl.fanglong.cn.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport;

import zfl.fanglong.cn.domain.User;

public class UserJDBCDAO extends NamedParameterJdbcDaoSupport implements UserDAO{
	

    public List<User> findUsers(String sql,User user){
    	final List<User> users = new ArrayList<User>();
    	Map<String,String>mmp = new HashMap<String,String>();
    	if(user!=null){
    		
    	}
    	this.getNamedParameterJdbcTemplate().query(sql,mmp, new RowMapper(){

			public Object mapRow(ResultSet arg0, int arg1) throws SQLException {
				// TODO Auto-generated method stub
				User user = new User();
				user.setUserName(arg0.getString("name"));
				user.setGender(arg0.getString("gender"));
				user.setPassword(arg0.getString("password"));
				user.setId(arg0.getLong("id"));
				users.add(user);
				return user;
			}
    		
    	});
    	return users;
}
    public void insertUser(String sql,User user){
      Map<String,String> mmp = new HashMap<String,String>();
      mmp.put("name", user.getUserName());
      mmp.put("password", user.getPassword());
      mmp.put("gender",user.getGender());
      //mmp.put("id",user.getId().toString());
    	getNamedParameterJdbcTemplate().update(sql, mmp);
    }
}
